<?php
namespace Home\Controller;
use Think\Controller;
include_once("Common.php");
include_once("mysqlha.php");
include_once("UpFileTool.class.php");
// 用于显示主页面
class ActivityController extends Controller
{
    
	//显示拼团专区
	public function showList(){
		$Model = M();
        $classifylist = $Model->Query("select * from categroy");
		$activitylist = $Model->Query("select * from h_activity_fenl_tu where activity_id=7");
		for($i=0;$i<sizeof($classifylist);$i++){
			$classifylist[$i]['ischeck'] = false;
			for($j=0;$j<sizeof($activitylist);$j++){
				if($classifylist[$i]['cateid'] == $activitylist[$j]['cateid']){
					$classifylist[$i]['ischeck'] = true;
					break;
				}
			}
		}
		
		
		$this->assign('classifylist',$classifylist);
		$this->display('Admin/niceActivity.php');
	}

	//获取客服列表
	public function getKeList(){
		$Model = M();
		$result = $Model->Query("select * from shop where iskefu=1");
		$user = array($result);
    	echo getSuccessJson($user);
	}

	public function getJiFen(){
		$Model = M();
		$userid = $_REQUEST['userid'];
		$return_volume = $Model->Query("select return_volume from user where userid=".$userid." ");
		$returnArr = array(
            "code"=>200,
            "return_volume"=>$return_volume[0]['return_volume']
		);
		echo json_encode($returnArr);
	}
	

    //修改分类
    public function OneChange(){
		
        $classifys = $_REQUEST['classifys'];
		$Model = M();
		del('h_activity_fenl_tu',"activity_id=7");
		for($i=0;$i<sizeof($classifys);$i++){
			$insertArr = array(
			   "cateid"=>$classifys[$i],
			   "activity_id"=>7
			);
			myinsert('h_activity_fenl_tu',$insertArr);
		}
		$returnArr = array(
			"code"=>200,
			"callbackType"=>"closeCurrent",
			"navTabId"=>"activity_list",
			"forwardUrl"=>"index.php?c=Activity&a=showList",
			"msg"=>"插入成功"
		);
		echo json_encode($returnArr);
    }
	
	//获取分类
	public function getActivity(){
		$Model = M();
		$result = $Model->Query("select t.*,t1.name from h_activity_fenl_tu t,categroy t1 where t.cateid=t1.cateid and t.activity_id = 7");
		$resultArr = array(
		   "code"=>200,
		   "result"=>$result
		);
		echo json_encode($resultArr);
	}
	
	//获取金钱详情
	public function getMD($money){
		$result = "";
		if($money>=0&&$money<100){
			$result=$money."件";
		}else if($money>=100&&$money<1000){
			$b = (int)$money/100;
			$result=$b."百件";
		}else if($money>=1000&&$money<10000){
			$b = (int)$money/1000;
			$result=$b."千件";
		}else if($money>=10000){
			$b = (int)$money/10000;
			$result=$b."万件";
		}
		return $result;
	}
	
	//获取9.9元专区商品
	public function getShopList(){
		$cateid = $_REQUEST['cateid'];
		$Model = M();
		$page = $_REQUEST['page'];
		$pagecount = $_REQUEST['pagecount'];
		
		if($page == null||$page<=0){
			$page=0;
		}

		if($pagecount == null||$pagecount<=0){
			$pagecount=6;
		}
        $cateids = $Model->Query("select * from h_activity_fenl_tu where activity_id=7");
        $cateidArr = array();
        for($i=0;$i<sizeof($cateids);$i++){
              $cateidArr[] = $cateids[$i]['cateid'];
        }
        $cateidArray = implode(',',$cateidArr);
		$startcount = $page*$pagecount;
		$result = $Model->Query("select xiaoliang,title,images,goodsid,price from goods where isnice=1 and xilie in (".$cateidArray.")   order by xiaoliang desc limit ".$startcount.",".$pagecount."");
		if($result){
			for($i=0;$i<sizeof($result);$i++){
				$result[$i]['images'] = explode(',',$result[$i]['images']); 
				$result[$i]['images'] = $result[$i]['images'][0];
				$xiaoliang = rand(1,1000);
				$result[$i]['xiaoliang'] = $this->getMD($xiaoliang);
			}
	    }
		$user = array($result);
    	echo getSuccessJson($user);
	}
}